﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;

public partial class Admin_CYBMXX_Manage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            PopulateDrop();
        }
        txtUserID.Attributes.Add("ReadOnly", "true");
    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        PopulateCYBMXX();
    }
    // 查询
    public void PopulateCYBMXX()
    {
        lvDate.DataSource = CYBMXX.GetAllByConditon(DongDong.Common.Misc.ConvertToInt(drpSheng.SelectedValue), DongDong.Common.Misc.ConvertToInt(drpShi.SelectedValue), DongDong.Common.Misc.ConvertToInt(drpQu.SelectedValue), txtName.Text, DongDong.Common.Misc.ConvertToInt(drpUserType.SelectedValue), txtTelphone.Text, txtPhone.Text, txtAddress.Text, DongDong.Common.Misc.ConvertToInt(hdlUserID.Value), DongDong.Common.Misc.ConvertToInt(drpSexType.SelectedValue), txtEmail.Text, txtCompanyName.Text, txtOnlineContact.Text);
        lvDate.DataBind();
    }
    // 获得用户名
    public string GetUserName(object UserID)
    {
        string Return = "暂无资料";
        Client objClient = Client.Get(DongDong.Common.Misc.ConvertToInt(UserID));
        if (objClient != null)
        {
            Return = "<a target='_blank' href='../../Admin/Client/Add.aspx?UserID=" + objClient.ID + "'>" + objClient.Username + "</a>";
        }
        return Return;
    }
    // 获得姓名（企业名称）
    public string GetUserAndCompanyName(object UserName, object CompanyName)
    {
        StringBuilder Return = new StringBuilder();
        Return.Append(UserName.ToString());
        if (CompanyName != null)
        {
            Return.Append("(");
            Return.Append(CompanyName.ToString());
            Return.Append(")");
        }
        return Return.ToString();
    }
    // 绑定下拉框
    public void PopulateDrop()
    {
        drpUserType.PopulateFromEnum<CYBMXX.typeUser>();
        drpUserType.Items.Insert(0, new ListItem("请选择", "0"));
        drpSexType.PopulateFromEnum<CYBMXX.typeSex>();
        drpSexType.Items.Insert(0, new ListItem("请选择", "0"));

        drpSheng.DataSource = S_Province.GetAll();
        drpSheng.DataValueField = "ProvinceID";
        drpSheng.DataTextField = "ProvinceName";
        drpSheng.DataBind();
        drpSheng.Items.Insert(0, new ListItem("请选择", "0"));

        drpShi.Items.Insert(0, new ListItem("请选择", "0"));

        drpQu.Items.Insert(0, new ListItem("请选择", "0"));
    }

    protected void drpSheng_TextChanged(object sender, EventArgs e)
    {
        int ParentID = DongDong.Common.Misc.ConvertToInt(drpSheng.SelectedValue);
        drpShi.DataSource = S_City.GetAllByCondition(ParentID, "");
        drpShi.DataValueField = "CityID";
        drpShi.DataTextField = "CityName";
        drpShi.DataBind();
        drpShi.Items.Insert(0, new ListItem("请选择", "0"));
    }

    protected void drpShi_TextChanged(object sender, EventArgs e)
    {
        int ParentID = DongDong.Common.Misc.ConvertToInt(drpShi.SelectedValue);
        drpQu.DataSource = S_District.GetAllByCondition(ParentID, "");
        drpQu.DataValueField = "DistrictID";
        drpQu.DataTextField = "DistrictName";
        drpQu.DataBind();
        drpQu.Items.Insert(0, new ListItem("请选择", "0"));
    }

    // 获得省市区名称
    public string GetShengShiQuName(object sheng, object shi, object qu)
    {
        string Return = "暂无资料";
        if (sheng != null || shi != null || qu != null)
        Return = S_District.GetPName_CName_RNameByPID_CID_RID(sheng, shi, qu);
        return Return;
    }

    protected void lvDate_ItemDeleting(object sender, ListViewDeleteEventArgs e)
    {
        int KeyID = DongDong.Common.Misc.ConvertToInt(lvDate.DataKeys[e.ItemIndex].Value);
        CYBMXX.BadDelete(KeyID);
        lvDate.EditIndex = -1;
        PopulateCYBMXX();
    }
    protected void Pager_PreRender(object sender, EventArgs e)
    {
        if (lvDate.Items.Count == 0)
            PopulateCYBMXX();
    }
}